using System;
using System.Collections.Generic;
using System.Text;
using DynamiteXml;

namespace Example.Engine
{
    public static class ExecuteEngineCode
    {

        public static void ModifyRecordWithDescendent(ItemWithXmlDS.ItemWithXmlRow row)
        {
            // Only Base xml object is applicable to the engine.
            ParentXml xml;

            // Get the IDynamiteXml implementing object. An invalid cast to the generic type will cause an exception.
            xml = DynamiteXmlLogic.Deserialize<ParentXml>(row.Xml);
            // Or, to avoid a null reference exception: 
            xml = DynamiteXmlLogic.Deserialize<ParentXml>(row.Xml, true);
            // Or, to cast manually:
            xml = DynamiteXmlLogic.Deserialize(row.Xml) as ParentXml;

            xml.ParentProperty++;

            row.Xml = DynamiteXmlLogic.Serialize(xml);
        }

        public static void ModifyRecordWithParent(ItemWithXmlDS.ItemWithXmlRow row)
        {
            ParentXml xml;

            // Get the IDynamiteXml implementing object. An invalid cast to the generic type will cause an exception.
            xml = DynamiteXmlLogic.Deserialize<ParentXml>(row.Xml);
            // Or, to avoid a null reference exception: 
            xml = DynamiteXmlLogic.Deserialize<ParentXml>(row.Xml, true);
            // Or, to cast manually:
            xml = DynamiteXmlLogic.Deserialize(row.Xml) as ParentXml;

            xml.ParentProperty++;

            row.Xml = DynamiteXmlLogic.Serialize(xml);
        }
    }
}
